#########################################################

work_dir=/public/home/xxf2019/20230331_colrNew/public_data/liver
config_path=${work_dir}/config
raw_fastq_path=${work_dir}/raw_fastq/
fastq_path=${work_dir}/fastq

mkdir -p ${config_path}
mkdir -p ${fastq_path}
mkdir -p ${work_dir}/fastq_checkMd5

conda activate nextflow_new

#########################################################

cd ${work_dir}

#########################################################
## 产生patient_list
echo "sample,seq_Type" > ${config_path}/patients.csv

find ${raw_fastq_path} | grep fastq.gz | awk -F'/' '{print $(NF)}' | sort -u | \
awk -F"_" '{OFS=","}{print $1,"WES"}' | sort -u >> ${config_path}/patients.csv

#########################################################
## 链接fastq文件
for sample in `cat ${config_path}/patients.csv | sed '1d' | awk -F',' '{print $1}'`
do
echo ${sample}

srx_name=`cat ${config_path}/sra_srx.list  | grep ${sample} | awk '{print $2}'`

file_name=`echo ${sample} `
fq_1=`find ${raw_fastq_path} | grep 1.fastq.gz | grep "/${file_name}_"`
fq_2=`find ${raw_fastq_path} | grep 2.fastq.gz | grep "/${file_name}_"`

ln -snf ${fq_1} ${fastq_path}/${srx_name}.R1.clean.fastq.gz
ln -snf ${fq_2} ${fastq_path}/${srx_name}.R2.clean.fastq.gz
done

#########################################################
## 最后分析样本的列表
## 样本的list

echo "sample,seq_Type" > ${config_path}/patients.csv
ls ${fastq_path}/ | awk -F'.' '{print $1",WES"}'  | sort -u >> ${config_path}/patients.csv

#########################################################

cd /public/home/xxf2019/20210409_NextFlow_GRCh37
work_dir=/public/home/xxf2019/20230331_colrNew/public_data/liver
inputdir=${work_dir}/fastq

cp -rf /public/home/xxf2019/20220915_gastric_multiple/config/Target* ${work_dir}/config

#########################################################

cd ~/20201204_NextFlowTest_FastqToBam
genome=grch37
genomicsdb=NA
use_genomicdb=F
seq_Type=WES

start=raw_fastq
sh WorkFlow.sh ${inputdir} ${work_dir} ${start} ${genome} ${genomicsdb} ${seq_Type}

inputdir=${work_dir}/results/Trim_fastq
start=trim_fastq
sh WorkFlow.sh ${inputdir} ${work_dir} ${start} ${genome} ${genomicsdb} ${seq_Type}

##################################################################################
## call somatic的突变
cat ${work_dir}/config/tumor_normal.class.list | awk -F'\t' '{OFS=","}{print $2,$3,"WES",$4,$5}' |\
sed 's/Tumor,Normal,WES/Tumor,Normal,seq_Type/' \
> ${work_dir}/config/tumor_normal.list

cat ${work_dir}/config/tumor_normal.list | awk -F',' '{print $2,$3}' | uniq > ${work_dir}/config/normal.list
cp -rf /public/home/xxf2019/20230331_colrNew/results/vcf/pon.vcf.gz* /public/home/xxf2019/20230331_colrNew/public_data/liver/results/vcf/

cd ~/20210318_NextFlow_somatic
work_dir=/public/home/xxf2019/20230331_colrNew/public_data/liver
inputdir=/public/home/xxf2019/20230331_colrNew/public_data/liver/results/bam
seq_Type=WES
genome=grch37
sh WorkFlow_all.sh ${work_dir} ${inputdir} ${seq_Type} ${genome}

start=callVariant
sh DNA-Seq-Somatic.sh --outdir ${work_dir}/results --design ${work_dir}/config/tumor_normal.list \
--normal ${work_dir}/config/normal.list \
-profile babs --inputdir ${inputdir} \
--start ${start} --pon ${work_dir}/results/vcf/pon.vcf.gz --seq_type ${seq_Type} --genome ${genome} -resume


##################################################################################
## TITAN
work_dir=/public/home/xxf2019/20230331_colrNew/public_data/liver
inputdir=/public/home/xxf2019/20230331_colrNew/public_data/liver/results/bam
seq_Type=WES
genome=grch37

start=titanCNA
sh DNA-Seq-Somatic.sh --outdir ${work_dir}/results --design ${work_dir}/config/tumor_normal.list --normal \
${work_dir}/config/normal.list -profile babs \
--inputdir ${inputdir} --start ${start} --pon ${work_dir}/results/vcf/pon.vcf.gz --seq_Type ${seq_Type} \
--genome ${genome} -resume

#########################################################
## 看bam文件的深度等信息
cd ~/20201204_NextFlowTest_FastqToBam

work_dir=/public/home/xxf2019/20230331_colrNew/public_data/liver
inputdir=/public/home/xxf2019/20230331_colrNew/public_data/liver/results/bam
genome=grch37
seq_type=WES
genomicsdb=""
use_genomicdb=""

start=bamqc
sh WorkFlow.sh ${inputdir} ${work_dir} ${start} ${genome} ${genomicsdb} ${use_genomicdb} ${seq_type}
